package com.hualan.sfzy.controller.system;

import com.hualan.sfzy.entity.system.Permission;
import com.hualan.sfzy.service.system.PermissionService;
import com.hualan.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName PermissionController
 * @Description TODO
 * @Author Mindy
 * @Date 2025年07月12日 下午3:10
 * @Version 1.0
 */
@RestController
public class PermissionController {

    @Autowired
    private PermissionService permissionService;

    @PostMapping("/permission")
    public Result add(@RequestBody Permission permission) {
        permissionService.add(permission);
        return  Result.success();
    }

    @DeleteMapping("/permission/{id}")
    public Result remove(@PathVariable Integer id) {
        permissionService.remove(id);
        return Result.success();
    }

    @DeleteMapping("/permission")
    public Result removeBath(Integer[] ids) {
        permissionService.removeBatch(ids);
        return Result.success();
    }

    @PutMapping("/permission/{id}")
    public Result edit(@RequestBody Permission permission) {
        permissionService.edit(permission);
        return Result.success();
    }

    @GetMapping("/permission/{id}")
    public Result findById(@PathVariable Integer id) {
        return Result.success(permissionService.findById(id));
    }

    @GetMapping("/permission/page")
    public Result findByPage(@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                          @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                          Permission permission) {
        return Result.success(permissionService.findByPage(pageNum, pageSize, permission));

    }

    @GetMapping("/permission")
    public Result find() {
        return Result.success(permissionService.find());
    }

}
